package disjunction.examples.entities
{
	import disjunction.*;
	
	import flash.events.Event;
	import flash.geom.Point;
	
	[SWF(width="550", height="400", backgroundColor="#000000", frameRate="500")]
	
	/**
	 * States Example.
	 *
	 * @author Nick Wiggill
	 */
	
	public class EntitiesDemo extends Game
	{
		//Update periods for View and Controller. One should be an integer multiple of
		//the other to avoid jerky-looking motion. View is usually quicker.
		public const CONTROLLER_PERIOD_MS:uint = 100; //10FPS
		public const VIEW_PERIOD_MS:uint = 20; //50FPS
		
		//If application loses processor focus, limit the max timedelta.
		public const UPDATE_TIMEOUT_MS:uint = 500;
		
		public function EntitiesDemo()
		{
			//we require a stage to be ready before passing it in.
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}
		
		public function addedToStageHandler(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
			//Register at least one game state for execution.
			registerState( new GameState("Demo",
				new DemoModel(),
				new DemoView(),
				new DemoController()) );

			//Prepare configuration.
			var config:GameStateConfig = new GameStateConfig();
			config.view = new ViewConfig(VIEW_PERIOD_MS, UPDATE_TIMEOUT_MS, this);
			config.controller =	new ControllerConfig(VIEW_PERIOD_MS, UPDATE_TIMEOUT_MS);
			
			//Use configuration to initialise and potentially begin execution of 
			//starting gamestate. Configuration of view and controller are separate from
			//construction, as states may be configured anew when reactivated for reuse.
			initialise("Demo", config);
		}
	}
}